package com.umpay.junit.test.xcx;

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.crypto.IllegalBlockSizeException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.umfwechat.common.code.RetCode;
import com.umfwechat.common.constant.CommonConsts;
import com.umfwechat.common.constant.ConfigConsts;
import com.umfwechat.common.prop.UmfPropModel;
import com.umfwechat.lightprogram.vo.SetAgentRateCfg;
import com.umfwechat.util.DesIDUtil;
import com.umfwechat.util.DesUtil;
import com.umfwechat.util.PropertyUtil;
import com.umfwechat.util.ReqMessageUtil;
import com.umfwechat.util.StringUtil;
import com.umfwechat.util.wx.WeixinHttpClientUtils;
import com.umpay.util.HttpUtil;

public class Aaaa {

	/**
	 * @param args
	 * @throws IllegalArgumentException 
	 * @throws IllegalBlockSizeException 
	 * @throws NoSuchAlgorithmException 
	 * @throws ParseException 
	 */
	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws IllegalBlockSizeException, IllegalArgumentException, NoSuchAlgorithmException, ParseException {
//		QuerySubAgent();//查询当前代理商信息
//		crmrequest();
//		CreateAgentManager();
//		Map<String, Object> productList=new HashMap<String, Object>();
//		storeProductList(productList);
//		System.out.println(productList);
//		Date a = new Date("2017-08-09");
		Date formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2017-08-10 21:02:54.880224");
		System.out.println(formatDate);
//		String format = new SimpleDateFormat("yyyy年MM月dd").format(formatDate);
//		System.out.println(format);
//		Date formatDate2 = new SimpleDateFormat("yyyy-MM").parse("2016-11");
//		System.out.println(formatDate2);
//		String format2 = new SimpleDateFormat("yyyy年MM月").format(formatDate2);
//		System.out.println(format2);
//		String dateSrc="2017-07-11";//日期2017-07-11
//		Pattern p = Pattern.compile();
//		Matcher m = p.matcher("18888888888");  
//	　　	System.out.println(m.matches()+"---"); 
//		String regex="^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
//		String a ="18888888888";
//		Pattern.matches(regex, a);
	}

	private static void storeProductList(Map<String, Object> productList) {
		productList.put("aa", "11");
		productList.put("bb", "22");
		productList.put("cc", "33");
		productList.put("dd", "44");
		
	}

	private static void CreateAgentManager() {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("rpid", "CRM666");//
		map.put("agentId", "E497527848");//Y694418971 E237040981 I014030141
		map.put("id", "18888888884");
		map.put("managerType", "0");//0-admin 1-普通操作员
		map.put("userName", "admin");
		map.put("mobileId", "18888888884");
		map.put("email", "214124@qq.com");
		String url = "http://10.10.77.76:7000/restUserManager/rest2/CreateAgentManager/CreateAgentManager.xml";
		System.out.println("url:"+url);
		
		Map<String,Object> retMap = null;
		try{
			retMap = HttpUtil.httpPostXStream2XStream(url,map,"UTF-8");
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(retMap);
	}
	private static void crmrequest() {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("rpid", "CRM666");//
		map.put("agentId", "Y694418971");//Y694418971 E237040981 I014030141
		map.put("userName", "admin");
		String url = "http://10.10.77.76:7000/restUserManager/rest2/CreateAgent/CreateAgent.xml";
		System.out.println("url:"+url);
		
		Map<String,Object> retMap = null;
		try{
			retMap = HttpUtil.httpPostXStream2XStream(url,map,"UTF-8");
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(retMap);
	}

	private static void demo() throws NoSuchAlgorithmException,
			IllegalBlockSizeException {
		MessageDigest md = MessageDigest.getInstance("SHA-1");
		// 对拼接后的字符串进行 sha1 加密
		byte[] digest = md.digest("admin123".getBytes());
		String str = byteToStr1(digest);
		System.out.println(str);
		System.out.println(str.length());
		
		
		
		System.out.println(1);
		DesUtil desUtil = new DesUtil("KSagZxG3");
		String enc_des = desUtil.enc_des("admin123");
		System.out.println(enc_des);
//		String str1 = DesUtil.str2HexStr(enc_des);
//		System.out.println(str);
////		
		String dec_des = desUtil.dec_des_crm("f865b53623b121fd34ee5426c792e5c33af8c227");
		System.out.println(dec_des);
		
		System.out.println(new Date().getTime());
		System.out.println(new Date().getDate());
		System.out.println(new Date().getDay());
		
	}
	@Test
    public void QuerySubAgent() {
		Map<String, Object> reqMap = ReqMessageUtil.makeReqCrmMap();
		reqMap.put("mainMerId", "68000193");//主商户号
		reqMap.put("mainMerName", "刘春燕");//主商户名称
		reqMap.put("followMerId", "68000194");//子商户号
		reqMap.put("followMerName", "子商户名称");//子商户名称
		reqMap.put("merCustState", "0");//商户客户关系状态
		reqMap.put("businessTag", "SAAS");//业务线标识
		String url = "http://10.10.67.76:9918/restUserManager/rest2/CreateMerCustRel/CreateMerCustRel.xml";
		System.out.println("url:"+url);
		
		Map<String,Object> retMap = null;
		try{
			retMap = HttpUtil.httpPostXStream2XStream(url,reqMap,"UTF-8");
		}catch(Exception e){
			e.printStackTrace();
		}
		System.out.println(retMap);
	}

	 private static String byteToStr1(byte[] byteArray) {  
        String strDigest = "";  
        for (int i = 0; i < byteArray.length; i++) {  
            strDigest += byteToHexStr1(byteArray[i]);  
        }  
        return strDigest;  
	 }  
	 /** 
	     * 将字节转换为十六进制字符串 
	     *  
	     * @param mByte 
	     * @return 
	     */  
    private static String byteToHexStr1(byte mByte) {  
        char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };  
        char[] tempArr = new char[2];  
        tempArr[0] = Digit[(mByte >>> 4) & 0X0F];  
        tempArr[1] = Digit[mByte & 0X0F];  
  
        String s = new String(tempArr);  
        return s;  
    }  
    /**
     * 加解密身份证号
     */
    @Test
    public void demo1(){
    	DesUtil desUtil = new DesUtil("KSagZxG3");
    	String id = null;
		try {
			id = desUtil.dec_des("99a4a2ab8851bf4dec6ef0cb699bfeb5b1d86a77fc1a25fe");
			System.out.println(id);
			String des = desUtil.enc_des("431022198903173160");
			System.out.println(des);
		} catch (IllegalBlockSizeException | IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    /**
     * 立码付低价费率10026接口
     */
    @Test
    public void demo2(){
    	com.umfwechat.common.ReqMessage reqMessage = ReqMessageUtil.makeReq();
		Map<String,Object> reqMap = reqMessage.getReqMap();
		reqMap.put("rpid", reqMessage.getRpid());
		reqMap.put("reqDate", reqMessage.getReqDate());
		reqMap.put("reqTime", reqMessage.getReqTime());
		reqMap.put("agentId", "Y669621624");//Y694418971 E237040981 I014030141
		reqMap.put("type", "18");//河
		String url = "http://10.10.179.93:8888/offline-serv1/10026";
//		String url = "http://10.10.77.94:8888/offline-serv1/10026";
		System.out.println("url:"+url);
		Map<String,Object> frontResult = null;
		try {
			frontResult = com.umpay.http.platform2.HttpUtil.httpPostForm2Xml
					(url, reqMap);
		} catch (Exception e2) {
			System.out.println(e2);
		}
		System.out.println(frontResult);
    }
    @Test
    public void demo3(){
//    	String accessToken = WeixinXcxUtil.getXcxAccessToken();
//    	System.out.println(accessToken);
		HttpClient client = HttpClients.createDefault();
    	String TOKENURL="https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN";
    	String requestUrl = TOKENURL.replace("ACCESS_TOKEN", "xgZxcf-55o-NwBgNCJx2k8sviyJP5dBvQ9mUrxYqmxnrUQH2PdlldKAuNV-EDD64lQHCtcrz0OzU2SEg6gfv58eVDmgwRVE-sAe9Q44pGC2Q_TpCjb0GyZNXJEDubVLNPVJaAJABHV");
		JSONObject jsonObject =null;
		String json="{\"offset\":0,\"count\":5}";
		try {
			jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, WeixinHttpClientUtils.POST_METHOD,json);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(jsonObject.toString());
    }
    /**
     * 		测试list
     */
    @Test
    public void demo5(){
    	Map<String, Object> map= new HashMap<String, Object>();
    	Map<String, Object> map2= new HashMap<String, Object>();
    	map.put("a", 11);
    	map.put("b", 22);
    	map2.put("c", 11);
    	map2.put("d", 22);
    	
		List<Map<String, Object>> list = new ArrayList<>();
		list.add(map);
		list.add(map2);
		System.out.println(list);
		String str = list.toString();
		System.out.println(str);
		try {
			JSONArray jArray = JSONArray.fromObject(str);
			List<Map<String, Object>> list1 =jArray.toList(jArray, Map.class);
			System.out.println("000");
		} catch (Exception e) {
			System.out.println(22);
			e.printStackTrace();
		}
		
    }
   
}
